package com.jdd.modules.parkcar.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.collection.ListUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jdd.common.constant.JddConstant;
import com.jdd.modules.parkcar.entity.ParkWhiteList;
import com.jdd.modules.parkcar.mapper.ParkWhiteListMapper;
import com.jdd.modules.parkcar.service.IParkWhiteListService;
import com.jdd.modules.parking.entity.ParkCarEnterLog;
import com.jdd.modules.system.vo.ParkWhiteListVO;
import com.jdd.modules.system.vo.SynchronousParkWhiteListVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.ListUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description: 白名单
 * @Author: jdd
 * @Date:   2021-02-18
 * @Version: V1.0
 */
@Service
@Slf4j
public class ParkWhiteListServiceImpl extends ServiceImpl<ParkWhiteListMapper,ParkWhiteList> implements IParkWhiteListService{

    @Resource
    private ParkWhiteListMapper parkWhiteListMapper;

    /**
     * 得到指定车场的是一位多车但状态标志为改变的白名单信息，结果根据车位号和创建时间排序，车位号小的，且创建时间为最新的数据在列表的前端
     *
     * @return 车位相同的车辆数据
     */
    @Override
    public List<ParkWhiteList> getSameParkNumberCars() {
        return parkWhiteListMapper.getSameParkNumberCars();
    }

    /**
     * 查询白名单车辆
     *
     * @param plateNo
     * @param licenseStatusY
     * @return
     */
    @Override
    public ParkWhiteList findByPlateNo(String plateNo, String licenseStatusY) {
        return parkWhiteListMapper.findByPlateNo(plateNo, licenseStatusY);
    }

    @Override
    public List<String> findWhiteAndBlackList() {
        return parkWhiteListMapper.findWhiteAndBlackList();
    }

    @Override
    public boolean zombieToBlack(ParkCarEnterLog parkCarEnterLog) {
        if(parkCarEnterLog.getPlateNo()!=null){
            //如果要转黑名单的在黑/白名单表里有，则不让转
            ParkWhiteList parkWhiteListByPlate = parkWhiteListMapper.findByPlateNo(parkCarEnterLog.getPlateNo(), JddConstant.ParkWhiteListConstant.LICENSE_STATUS_Y);
            if(parkWhiteListByPlate!=null){
                return false;
            }
        }
        ParkWhiteList parkWhiteList = new ParkWhiteList();
        BeanUtils.copyProperties(parkCarEnterLog, parkWhiteList);
        parkWhiteList.setStatus("Y");
        parkWhiteList.setLicenseType(2);
        parkWhiteList.setRemark("滞留车转黑名单");
        //滞留车转的黑名单暂时设置无限期
        parkWhiteList.setIsForever(JddConstant.StringNumber.STRING_ONE);
        return this.save(parkWhiteList);
    }

    @Override
    public void batchAdd(List<SynchronousParkWhiteListVO> parkBlackLists) {
         parkWhiteListMapper.batchAdd(parkBlackLists);
    }
}
